package com.yuwei.module_cash_desk

import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.lib_http.entity.CashDeskEntityItem
import com.google.zxing.BarcodeFormat
import com.journeyapps.barcodescanner.BarcodeEncoder
import com.umeng.socialize.ShareAction
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import com.umeng.socialize.media.UMImage
import com.umeng.socialize.media.UMWeb
import com.yuwei.module_cash_desk.databinding.ActivityBillPayBinding

/**
 * 智慧园区-04-收银台-扫码支付-V1.1-20250511
 */
@Route(path = RouterPath.MODULE_BILL_PAY_ACTIVITY)
class BillPayActivity : BaseMvvmActivity<ActivityBillPayBinding>() {
    @Autowired
    lateinit var cashDesk: CashDeskEntityItem
    @JvmField
    @Autowired
    var money = 0

    @RequiresApi(Build.VERSION_CODES.M)
    override fun initViews() {
        binding.billPayBack.setOnClickListener {
            finish()
        }
        ARouter.getInstance().inject(this)
        binding.projectName.text = cashDesk.projectName
        binding.payerName.text = "户主:${cashDesk.payerName}"
        binding.total.text = "￥${money}.00"
        val code = "￥${money}"
        val barcode = BarcodeEncoder()
        val bitmap = barcode.encodeBitmap(
            code,
            BarcodeFormat.QR_CODE,
            200,
            200
        )
        binding.pay.setOnClickListener {
            if (!UMShareAPI.get(this).isInstall(this, SHARE_MEDIA.QQ)) {
                // 提示用户安装QQ
                ToastUtils.showShort("请安装QQ")
                return@setOnClickListener
            }
            val web = UMWeb("https://ds.alipay.com/")
            web.title = "支付二维码" //标题
            val umImage = UMImage(this,bitmap)
            web.setThumb(umImage) //缩略图
            web.description = "缴费二维码,须缴付:￥${money}"//描述
            ShareAction(this)
                .withMedia(web)
                .open()
        }
        // 显示生成的二维码图片
        binding.twoCode.setImageBitmap(bitmap)
    }
    override fun observeDataChange() {

    }

    override fun getLayoutId(): Int = R.layout.activity_bill_pay

}